
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"


** MAKE TABLE F.1

import delimited "${Inputs}\Cook_experian_sumstats.tex", clear

	replace v1 = v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5 + "," + v6 + "," + v7 if !mi(v7)
	
	drop v2-v7
	drop if !regexm(v1, "&")
	replace v = subinstr(v, "\sym{", "", .)
	replace v = subinstr(v, "\hspace{0.1cm} ", "", .)
	replace v = subinstr(v, "\emph{", "", .)
	replace v = subinstr(v, "\multicolumn{2}{c}{", "", .)
	replace v = subinstr(v, "}", "", .)
	replace v = subinstr(v, "\\", "", .)

	split v1, parse("&")
	drop if regexm(v12, "Evicted")
	drop if regexm(v11, "characteristics|Quarters 1-8")
	
	preserve 
		keep if regexm(v11, "Observations")
		rename (v12 v14 v16) (numevic numnon numran)
		drop v*
		gen col = "x"
		reshape long num, i(col) j(group) string
		destring num, replace 
		gen num2 = string(num, "%12.0fc")
		drop num 
		rename num2 num 
		gen item = "obs"
		
		tempfile cook_obs 
		save `cook_obs'
	restore 
		
	drop if regexm(v11, "Observations")	
	rename 	(v12 v13 v14 v15 v16 v17) ///
			(numevic_mean numevic_sd numnon_mean numnon_sd numran_mean numran_sd)
	drop if mi(numevic_sd)
	drop v1 

	drop if v11=="Total bal. collections"
	
	gen 	col = "age" 	if v11=="Age at filing"
	replace col = "fem" 	if v11=="Female"
	replace col = "cred" 	if v11=="Credit Score"
	replace col = "zero"	if v11=="No Open Revolving Account"
	replace col = "deli" 	if v11=="Total balance: collections and delinquencies"
	replace col = "auto"	if v11=="Any Auto Loan or Lease"
	replace col = "payi" 	if v11=="Any Payday Inquiry $\times$ 100"
	replace col = "inde" 	if v11=="Financial Health Index"
	
	reshape long num , i(v11) j(type) string
	replace num = trim(num)
	split type, parse("_")
	rename (type1 type2) (group item)
	drop v11 type 
	
	replace num = "521" if num=="520.661"
	replace num = "(65)" if num=="(65.186)"
	replace num = "536" if num=="535.946"
	replace num = "(75)" if num=="(75.039)"
	replace num = "606" if num=="605.557"
	replace num = "(108)" if num=="(108.309)"
	replace num = "2,340" if num=="2,339.987"
	replace num = "(4,953)" if num=="(4,953.389)"
	replace num = "2,301" if num=="2,301.119"
	replace num = "(5,014)" if num=="(5,013.874)"
	replace num = "1,451" if num=="1,450.814"
	replace num = "(4,410)" if num=="(4,410.369)"
	replace num = "605" if num=="605.414"
	replace num = "(108)" if num=="(108.358)"
	replace num = "1,458" if num=="1.458.082"
	replace num = "(4,420)" if num=="(4,420.324)"
	
	append using `cook_obs'
	
	gen geo = "cc"
	
	tempfile cc_summ_stats_ready
	save `cc_summ_stats_ready'
	

use "${Inputs}\NY_credit_sumstats.dta", clear

	gen 	nummean = string(mean, "%10.3fc") if regexm(outcome, "Female|Revolv|Auto|Inde")
	replace nummean = string(mean, "%10.0fc") if regexm(outcome, "Credit|Balance|Deli")
	
	gen 	numsd = "(" + string(sd, "%10.3fc") + ")" if regexm(outc, "Fema|Revo|Auto|Inde")
	replace numsd = "(" + string(sd, "%10.0fc") + ")" if regexm(outc, "Cre|Bala|Deli")
	
	gen 	numobs = string(N, "%10.0fc")  
	
	drop if regexm(outcome, "Female")
	gen 	col = "inde" if outcome=="Index"
	replace col = "cred" if outcome=="Credit Score"
	replace col = "zero" if outcome=="No Revolving Account"
	replace col = "deli" if outcome=="Deliquencies and Collections"
	replace col = "auto" if outcome=="Any Auto Loan"
	
	gen 	group = "evic" 	if specification=="Evicted"
	replace group = "non" 	if specification=="Not Evicted"
	
	keep num* col group 
	reshape long num, i(col group) j(item) string
	gen geo = "ny"
	
	replace col = "x" if item=="obs"
	duplicates drop 
	
	append using `cc_summ_stats_ready'

	isid col group item geo 
	
	levelsof col, local(columns)
	levelsof group, local(groups)
	levelsof item, local(items)
	levelsof geo, local(geos)
	
foreach colx in `columns' {
	local id1 = "`colx'"
		
	foreach groupx in `groups' {
		local id2 = "`groupx'"
			
		foreach itemx in `items' {
			local id3 = "`itemx'"
				
			foreach geox in `geos' {
				local id4 = "`geox'"

				levelsof num if col=="`colx'" & group=="`groupx'" & item=="`itemx'" & geo=="`geox'", clean ///
				local(`id1'_`id2'_`id3'_`id4')	
				
			}	
		}
	}
}

 
texdoc init "${Outputs}/Supplementary data_Table_F1.tex", replace force 
tex \begin{tabular}{l c c c c c c} \hline \toprule ///
	& \multicolumn{3}{c}{\textbf{Cook County}} & & \multicolumn{2}{c}{\textbf{New York}} \\
tex	\cmidrule{2-4} \cmidrule{6-7}
tex	& Evicted & Not Evicted & Random Sample & & Evicted & Not Evicted \\
tex	& (1) & (2) & (3) & & (4) & (5) \\
tex	\cmidrule{2-4} \cmidrule{6-7}
tex \textit{Person Characteristics} & & & & & & \\
tex ~~~Age at filing & `age_evic_mean_cc' & `age_non_mean_cc' & `age_ran_mean_cc' & & & \\
tex 				 & `age_evic_sd_cc' & `age_non_sd_cc' & `age_ran_sd_cc' & & & \\

tex ~~~Female  		& `fem_evic_mean_cc' & `fem_non_mean_cc' & `fem_ran_mean_cc' & & & \\
tex 				& `fem_evic_sd_cc' & `fem_non_sd_cc' & `fem_ran_sd_cc' & & & \\

tex & & & & & & \\ 
tex $x \textit{Outcomes: Quarters 1-8 Before Filing} & & & \\

tex $x ~~~Financial health index 	& `inde_evic_mean_cc' 	& `inde_non_mean_cc' 	& `inde_ran_mean_cc' 	& & `inde_evic_mean_ny' & `inde_non_mean_ny' \\
tex 					& `inde_evic_sd_cc' 	& `inde_non_sd_cc' 		& `inde_ran_sd_cc' 		& & `inde_evic_sd_ny' 	& `inde_non_sd_ny' \\

tex $x ~~~Credit score 	& `cred_evic_mean_cc' 	& `cred_non_mean_cc' 	& `cred_ran_mean_cc' 	& & `cred_evic_mean_ny' & `cred_non_mean_ny' \\
tex 					& `cred_evic_sd_cc' 	& `cred_non_sd_cc' 		& `cred_ran_sd_cc' 		& & `cred_evic_sd_ny' 	& `cred_non_sd_ny' \\

tex $x ~~~No open revolving account	& `zero_evic_mean_cc' 	& `zero_non_mean_cc' 	& `zero_ran_mean_cc' 	& & `zero_evic_mean_ny' & `zero_non_mean_ny' \\
tex 					& `zero_evic_sd_cc' 	& `zero_non_sd_cc' 		& `zero_ran_sd_cc' 		& & `zero_evic_sd_ny' 	& `zero_non_sd_ny' \\

tex $x ~~~Total balance: collections and delinquencies 	& `deli_evic_mean_cc' 	& `deli_non_mean_cc' 	& `deli_ran_mean_cc' 	& & `deli_evic_mean_ny' & `deli_non_mean_ny' \\
tex 					& `deli_evic_sd_cc' 	& `deli_non_sd_cc' 		& `deli_ran_sd_cc' 		& & `deli_evic_sd_ny' 	& `deli_non_sd_ny' \\

tex $x ~~~Any auto loan or lease 	& `auto_evic_mean_cc' 	& `auto_non_mean_cc' 	& `auto_ran_mean_cc' 	& & `auto_evic_mean_ny' & `auto_non_mean_ny' \\
tex 					& `auto_evic_sd_cc' 	& `auto_non_sd_cc' 		& `auto_ran_sd_cc' 		& & `auto_evic_sd_ny' 	& `auto_non_sd_ny' \\

tex \midrule 
tex Observations 	& `x_evic_obs_cc' & `x_non_obs_cc' & `x_ran_obs_cc' & &  `x_evic_obs_ny' & `x_non_obs_ny' \\

tex \bottomrule \\ 
tex \end{tabular}
texdoc close	
	

